const express = require("express");
const router = express.Router();

const { timeTrans } = require("../../../utils");
const { addPublish } = require("../../../model/weixin/admin/publish");

/* notice增删改查 */

// 添加notice数据
router.post("/add", async (req, res, next) => {
  let { publish_id, list, title, intro, tag, sellStatus, coverImg, context } =
    req.body;
  console.log(
    publish_id,
    list,
    title,
    intro,
    tag,
    sellStatus,
    coverImg,
    context
  );
  publish_id = Number(publish_id);
  coverImg = "http://localhost:3333/images/" + coverImg;
  addPublish([
    publish_id,
    list,
    title,
    intro,
    tag,
    sellStatus,
    coverImg,
    context,
  ])
    .then(() => {
      res.send({
        code: 200,
        msg: "添加广告轮播成功",
      });
    })
    .catch((err) => {
      res.send({
        code: 500,
        msg: "添加广告轮播失败",
        err,
      });
    });
});

module.exports = router;
